﻿using System;
using System.Collections.Generic;
using System.IO;
using FDFtpSync.Core;
using FDFtpSync.Entities;
using FDFtpSync.Ioc;
using FDFtpSync.Utils;
using Microsoft.Extensions.DependencyInjection;
using Topshelf;

namespace FDFtpSync.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = new DefaultContainer();
            SyncContext.Current.InitClient(new JsonSerializer());
            SyncContext.Current.Register(c);
            c.Register(options =>
             {
                 options.AddScoped<ILogger, DefaultLogger>();
                 switch (SyncContext.Current.GetSyncConfig<ClientSyncConfig>().SyncServerType)
                 {
                     case SyncServerType.Http:
                         options.AddScoped<IFileSyncServer, HttpFileSyncServer>(); break;
                     case SyncServerType.Ftp:
                         options.AddScoped<IFileSyncServer, FtpFileSyncServer>(); break;
                     default:
                         break;
                 }
             })
             .Build();

            HostFactory.Run(cfg =>
            {
                cfg.Service<FileSyncService>();
                cfg.SetDescription("底包同步服务");
                cfg.SetDisplayName("LeeFtp.PackageSyncService");
                cfg.SetServiceName("LeeFtp.PackageSyncService");
            });
        }
    }
}
